﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets {
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.system.*;
    
    import net.wooga.pets.constants.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.utils.*;
    
    import reprise.core.*;
	import com.adobe.serialization.json.*;

	[swf(width="760",height="660")]
    public class Pets extends Application {

        private var _robotlegsContext:PetsContext;
        private var _initialLoader:IInitialLoader;
		private var _fileInfoLoader:URLLoader;
        private var _language:String;
        private var _assetsBaseUrl:String;// = ""
		private var _fileInfo:Object;

        public static var CSS_URL:String;
        private static var _instance:Pets;

        override protected function initialize():void{
            Security.allowDomain("*");
            _instance = this;
            addEventListener(EventConstants.ON_PRELOADING_COMPLETE, this.onPreloadingComplete);
            this._initialLoader = (((parent.parent as IInitialLoader)) || (null));
            //this._assetsBaseUrl = stage.loaderInfo.parameters.assetsBaseUrl;
			loadFileList();
        }
        private function getRandomURL(_arg1:String):String{
            var _local2:int = Numbers.randomIntBetween(1, 1);
            return (Strings.replacePattern(_arg1, "num", _local2.toString()));
        }
        override protected function startApplication():void{
            m_rootElement.cssID = this.getLocale().toLowerCase();
            l();
            zz_monitor(true);
            stage.scaleMode = StageScaleMode.EXACT_FIT;
            stage.align = StageAlign.TOP_LEFT;
            this._robotlegsContext = new PetsContext(m_rootElement);
            if (this.localVersion){
                new PetsDebugInterface(m_rootElement, loaderInfo.parameters.rootPath);
            };
        }
		private function loadFileList():void{
			this._fileInfoLoader = new URLLoader();
			var _local1:String = "";
			var _local2:Date = new Date();
			var _local3:String = "file_info.json?"+_local2.getTime();
			_local1 = "http://hh.wooga.com/" + _local3;
			var _local4:URLRequest = new URLRequest(_local1);
			this._fileInfoLoader.addEventListener(Event.COMPLETE,this.onFileListLoad);
			this._fileInfoLoader.load(_local4);
		}
		private function onFileListLoad(e:Event):void{
			this._fileInfo = JSON.decode(this._fileInfoLoader.data);
			this._assetsBaseUrl = "http://cdn4.wooga.com/";
			CSS_URL = "style/flash.css";
			if (this.fileInfo){
				CSS_URL = (this._assetsBaseUrl + this.getRandomURL(this.fileInfo[CSS_URL]["url"]));
			} else {
				CSS_URL = (this._assetsBaseUrl + CSS_URL);
			};
			this.loadFonts();
			
		}
        private function onPreloadingComplete(_arg1:Event):void{
            if (this._initialLoader){
                this._initialLoader.removePreloaderDisplay();
            };
        }
        public function get fileInfo():Object{
            return ((this._fileInfo) ? this._fileInfo : {});
        }
        public function get localVersion():Boolean{
            var _local1 = !((stage.loaderInfo.url.indexOf("file:") == -1));
            _local1 = ((_local1) || (!((stage.loaderInfo.url.indexOf("localhost") == -1))));
            return (_local1);
        }
        private function loadFonts():void{
            this._language = this.getLocale().toLowerCase().split("_")[0];
            var _local1:String = ((((GameConstants.ASSETS_PATH + "locale/") + this._language) + "/") + GameConstants.FONT_ASSETS);
            var _local2:String = (this._assetsBaseUrl + _local1);
            //if (((this._initialLoader) && (!(this.localVersion)))){
            if (this.fileInfo[_local1]){
                _local2 = (this._assetsBaseUrl + this.getRandomURL(this.fileInfo[_local1]["url"]));
                    //unresolved jump
            };
            //};
            var _local3:Loader = new Loader();
            _local3.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onFontsLoaded);
            _local3.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.ioErrorHandler);
			var context:LoaderContext = new LoaderContext(true);
			context.securityDomain = SecurityDomain.currentDomain;
            var _local4:URLRequest = new URLRequest(_local2);
            _local3.load(_local4,context);
        }
        private function ioErrorHandler(_arg1:IOErrorEvent):void{
        }
        private function onFontsLoaded(_arg1:Event):void{
            var _local2:Class;
            _local2 = (_arg1.target.applicationDomain.getDefinition((("net.wooga.pets.assets.fonts." + this._language) + ".FontAssets")) as Class);
            super.initialize();
        }
        private function getLocale():String{
            var _local1:String = "zh";
            var _local2:String = "de,en,es,fr,it,pt,tr";
            return (EnvironmentModel.getSupportedLocale(_local1, _local2));
        }

        public static function get instance():Pets{
            return (_instance);
        }

    }
}//package net.wooga.pets 
